/*
 *  Laboratorio de Finanzas Computacionales
 */

package bm.actions;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;
import org.apache.struts.actions.DispatchAction;

public class Contador extends DispatchAction {
    
    
    public ActionForward unspecified(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response) throws Exception {
        
        Integer cont;
        
        if (request.getSession().getAttribute("cont") == null){
            cont = new Integer(0);
            
            request.getSession().setAttribute("cont", cont);
            
        }else{
            cont = (Integer) request.getSession().getAttribute("cont");
        }
        
        
        request.getSession().setAttribute("cont", cont);
        request.setAttribute("cont", cont);
        
        return mapping.findForward("success");
    }
    
    
    public ActionForward suma(ActionMapping mapping,ActionForm form,
            javax.servlet.http.HttpServletRequest request,
            javax.servlet.http.HttpServletResponse response) throws Exception {
        
        Integer cont = (Integer) request.getSession().getAttribute("cont");
        
        
        cont = new Integer(cont.intValue() + 1);
        
        
        request.getSession().setAttribute("cont", cont);
        request.setAttribute("cont", cont);
        
        return mapping.findForward("success");
    }
    
    
    public ActionForward resta(ActionMapping mapping,ActionForm form,
            javax.servlet.http.HttpServletRequest request,
            javax.servlet.http.HttpServletResponse response) throws Exception {
        
        Integer cont = (Integer) request.getSession().getAttribute("cont");
        
        
        cont = new Integer(cont.intValue() - 1);
        
        
        request.getSession().setAttribute("cont", cont);
        request.setAttribute("cont", cont);
        
        return mapping.findForward("success");
    }
    
    
}

